home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / systems / mac / oztex-german / OzTeX-1.4d.sit.bin / OzTeX 1.4 / PS-files / DVItoPS.ps < prev    next >
Text File  |  1992-01-15  |  10KB  |  304 lines

  1. %!
  2. % This is the prolog used by OzTeX 1.4 to convert a DVI file into PostScript.
  3.  
  4. % Set dev to "LW" if LaserWriter, "LINO" if Linotronic, or "?" if unknown:
  5.  
  6. /dev (?) def
  7. statusdict /product known
  8. { statusdict /product get dup
  9.   (LaserWriter) anchorsearch { pop pop /dev (LW)   def } { pop } ifelse
  10.   (Linotype)    anchorsearch { pop pop /dev (LINO) def } { pop } ifelse
  11. } if
  12.  
  13. % OzTeX calls @setup with the following parameters:
  14. % resolution (integer), landscape (boolean), horizontal and vertical offsets
  15. % (integers that are used to position the TeX origin correctly) .
  16.  
  17. /@setup {                                    % set up OzTeX's coordinate system
  18.  
  19. /voff exch def
  20. /hoff exch def
  21. /land exch def
  22. /res  exch def
  23.  
  24. dev (?) eq                                    % unknown device?
  25. { land
  26.   {                                            % landscape
  27.      90 rotate                                % rotate axes 90deg anticlockwise
  28.      72 res div dup neg scale            % units now device dots
  29.      res dup translate                    % move to TeX origin
  30.      voff neg hoff translate            % adjust TeX origin if necessary
  31.   }
  32.   {                                            % portrait
  33.      72 res div dup neg scale            % units now device dots
  34.      res -10.7 res mul translate        % move to TeX origin
  35.      hoff voff translate                    % adjust TeX origin if necessary
  36.   } ifelse
  37. } if
  38.  
  39. dev (LW) eq                                    % LaserWriter?
  40. { land
  41.   {                                            % landscape
  42.      % rotate/scale/translate can cause scaling problems, so use setmatrix:
  43.      version cvr 38.0 le
  44.      { [ 0 -1 1 0 235 hoff add 3100 voff add ] setmatrix } % LaserWriter
  45.      { version cvr 47.0 lt
  46.      { [ 0 -1 1 0 235 hoff add 3130 voff add ] setmatrix } % LaserWriter Plus
  47.      { [ 0 -1 1 0 235 hoff add 3160 voff add ] setmatrix } % LaserWriter II NTX
  48.                       % add y to move TeX origin down by y pixels
  49.                                         % add x to move TeX origin LEFT by x pixels
  50.      ifelse } ifelse
  51.   }
  52.   {                                            % portrait
  53.      % scale/translate can cause scaling problems, so use setmatrix:
  54.      version cvr 38.0 le
  55.      { [ 1 0 0 1 235 hoff add 190 voff add ] setmatrix }    % LaserWriter
  56.      { version cvr 47.0 lt
  57.      { [ 1 0 0 1 235 hoff add 215 voff add ] setmatrix }    % LaserWriter Plus
  58.      { [ 1 0 0 1 235 hoff add 265 voff add ] setmatrix }    % LaserWriter II NTX
  59.                      % add x to move TeX origin right by x pixels
  60.                                         % add y to move TeX origin down by y pixels
  61.      ifelse } ifelse
  62.   } ifelse
  63. } if
  64.  
  65. dev (LINO) eq                                % Linotronic?
  66. { land
  67.   {                                            % landscape
  68.      90 rotate                                % rotate axes 90deg anticlockwise
  69.      72 res div dup neg scale            % units now device dots
  70.      res dup translate                    % move to TeX origin
  71.      voff neg hoff translate            % adjust TeX origin if necessary
  72.   }
  73.   {                                            % portrait
  74.      newpath clippath pathbbox            % push LLx LLy URx URy (URy = ht in pts)
  75.      /paperht exch 72 div def            % paper height in inches
  76.      pop pop pop                            % remove URx LLy LLx
  77.      72 res div dup neg scale            % units now device dots
  78.      res paperht res mul neg res add
  79.                                   translate    % move to TeX origin
  80.      hoff voff translate                    % adjust TeX origin if necessary
  81.   } ifelse
  82. } if
  83.  
  84. /mtrx 6 array def
  85. mtrx currentmatrix pop                    % save our new transformation matrix
  86.  
  87. } def                                            % end of @setup
  88.  
  89. % @saveVM and @restoreVM are only used if we are conserving VM
  90. % by downloading font bitmaps more often:
  91.  
  92. /@saveVM {/prefontVM save def} def
  93. /@restoreVM {prefontVM restore} def
  94.  
  95. /@newfont                                    % create new font dict
  96. { /maxchcode exch def
  97.   /fontid exch def
  98.   fontid 7 dict def
  99.   fontid load begin
  100.       /FontType 3 def
  101.       /FontMatrix [1 0 0 -1 0 0] def    % -1 because y scale is negative
  102.       /FontBBox [0 0 1 1] def
  103.       /BitMaps maxchcode 1 add array def
  104.       /BuildChar {CharBuilder} def
  105.       /Encoding maxchcode 1 add array def
  106.       0 1 maxchcode {Encoding exch /.notdef put} for
  107.       end
  108.   fontid fontid load definefont pop
  109. } def
  110.  
  111. % The char data, a bitmap descriptor, is an array with 6 elements:
  112.  
  113. /ch-image    {ch-data 0 get} def        % the hex string image
  114. /ch-width    {ch-data 1 get} def        % the number of pixels across
  115. /ch-height    {ch-data 2 get} def        % the number of pixels tall
  116. /ch-xoff        {ch-data 3 get} def        % number of pixels to left of origin
  117. /ch-yoff        {ch-data 4 get} def        % number of pixels below origin
  118. /ch-advw        {ch-data 5 get} def        % advance width
  119.  
  120. % The following character builder looks up the char data in the BitMaps array
  121. % and paints the character:
  122.  
  123. /CharBuilder                                % image one char
  124. { /ch-code exch def                        % save the char code
  125.   /font-dict exch def                    % and the font dict
  126.   /ch-data font-dict /BitMaps get
  127.   ch-code get def
  128.       ch-advw 0
  129.       ch-xoff neg ch-height ch-yoff sub 1 sub neg    % -xo , -(ht-yo-1)
  130.       ch-width ch-xoff sub 1 sub ch-yoff                % (wd-xo-1) , yo
  131.   setcachedevice
  132.       ch-width ch-height true
  133.       [1 0 0 -1 ch-xoff ch-yoff]        % bitmap sent top to bottom
  134.       {ch-image}
  135.   imagemask
  136. } def
  137.  
  138. /sf {setfont} def                            % set current font
  139.  
  140. /dc                                            % define new character
  141. { /ch-code exch def
  142.   /ch-data exch def
  143.  
  144.   % The following code should be enabled if you have an old LaserWriter.
  145.   % It attempts to overcome a bug that causes the printer to crash
  146.   % and print a test page rather then report a VMerror.
  147.   %
  148.   % vmstatus                                % returns: savelevel vmused vmmax
  149.   % 10000 sub gt                            % is vmused > (vmmax-10000)?
  150.   %    { pop VMERROR }                    % causes error message (avoiding crash)
  151.   %    { pop }                                % pop savelevel
  152.   % ifelse
  153.  
  154.   currentfont /BitMaps get ch-code ch-data put
  155.   currentfont /Encoding get ch-code
  156.   dup (   ) cvs cvn put                    % generate unique name
  157. } bind def
  158.  
  159. /@bop0 {pop} def                            % begin DVI page n
  160.  
  161. /@bop1                                        % begin setting DVI page n
  162. { pop                                            % throw away page number
  163.   initgraphics                                % start with a clean slate
  164.   mtrx setmatrix                            % switch to our TeX coordinate system
  165.   /prepageVM save def                    % save state of VM at start of page
  166. } def
  167.  
  168. /@eop                                            % end DVI page n
  169. { pop                                            % throw away page number
  170.   prepageVM restore                        % restore VM to state at start of page
  171.   showpage
  172. } def
  173.  
  174. /@end { } def                                % end of file
  175.  
  176. % h and s are used to typeset downloaded bitmap fonts:
  177.  
  178. /h {exch 0 rmoveto show} bind def    % move right by dh and show (...)
  179.  
  180. /s {3 1 roll moveto show} bind def    % move to h,v and show (...)
  181.  
  182. % H and S are used to typeset resident PostScript fonts.
  183. % We can't use relative horizontal positioning because the advance widths in
  184. % a PostScript font are not integers and rounding errors would accumulate:
  185.  
  186. /H {exch v moveto show} bind def        % move to h,v and show (...)
  187.  
  188. /S                                                % ditto, and save v position
  189. { 3 1 roll
  190.   1 add                                        % v+1 to match baseline of bitmap fonts
  191.   dup /v exch def
  192.   moveto show
  193. } bind def
  194.  
  195. % Some fine-tuning of the code used to draw a rule is necessary:
  196.  
  197. dev (LW) eq                                    % LaserWriter?
  198. version cvr 38.0 le and                    % and version <= 38.0?
  199. {
  200.   /r                                            % set a wd by ht rule at h,v
  201.   { newpath
  202.      1 add moveto                            % move to h,v+1 (don't ask me why)
  203.      /ht exch 1 sub def                    % reduce height by 1
  204.      /wd exch 1 sub def                    % ditto for width
  205.      wd 0 rlineto
  206.      0 ht neg rlineto
  207.      wd neg 0 rlineto
  208.      fill
  209.   } bind def
  210. }
  211. {
  212.   /r                                            % set a wd by ht rule at h,v
  213.   { newpath
  214.      moveto                                    % move to h,v
  215.      /ht exch 1 sub def                    % reduce height by 1
  216.      /wd exch 1 sub def                    % ditto for width
  217.      wd 0 rlineto
  218.      0 ht neg rlineto
  219.      wd neg 0 rlineto
  220.      fill
  221.   } bind def
  222. } ifelse
  223.  
  224. % Following procedures are invoked as the result of \special{file}.
  225. % We change all scaling and graphics back to defaults, but shift the origin
  226. % to the current position on the page:
  227.  
  228. /@bsp
  229. { /vmag exch def                            % vertical scaling
  230.   /hmag exch def                            % horizontal scaling
  231.   moveto                                        % move to h,v
  232.   gsave
  233.   /prespecialVM save def                % save showpage, TeX procedures etc.
  234.   currentpoint transform
  235.   initgraphics itransform translate
  236.   hmag vmag scale
  237.   land { 90 rotate } if                    % rotate axes if landscape
  238.   /showpage { } def                        % user does not have to remove showpage
  239. } bind def
  240.  
  241. /@esp
  242. { prespecialVM restore                    % restore saved showpage value etc.
  243.   grestore
  244. } bind def
  245.  
  246. % Following procedures are invoked as the result of \special{epsf: file}.
  247. % Note that @bepsf and @eepsf are currently identical to @bsp and @esp
  248. % but it is a good idea to allow for future changes:
  249.  
  250. /@bepsf
  251. { /vmag exch def                            % vertical scaling
  252.   /hmag exch def                            % horizontal scaling
  253.   moveto                                        % move to h,v
  254.   gsave
  255.   /prespecialVM save def                % save showpage, TeX procedures etc.
  256.   currentpoint transform
  257.   initgraphics itransform translate
  258.   hmag vmag scale
  259.   land { 90 rotate } if                    % rotate axes if landscape
  260.   /showpage { } def                        % user does not have to remove showpage
  261. } bind def
  262.  
  263. /@eepsf
  264. { prespecialVM restore                    % restore saved showpage value etc.
  265.   grestore
  266. } bind def
  267.  
  268. % Here is the code to handle bitmaps generated by PICT/PNTG \specials:
  269.  
  270. /@bitmap
  271. { /vmag exch def                            % vertical scaling
  272.   /hmag exch def                            % horizontal scaling
  273.   /vres exch def                            % vertical resolution of bitmap
  274.   /hres exch def                            % horizontal resolution of bitmap
  275.   /ht exch def                                % height
  276.   /wd exch def                                % width
  277.   /hexstring ht string def
  278.   gsave
  279.      1 add translate                        % set origin to h,v+1
  280.      res hres div wd mul hmag mul
  281.      res vres div ht mul vmag mul neg scale
  282.      wd ht true
  283.      [ wd 0 0 ht neg 0 ht ]
  284.      { currentfile hexstring readhexstring pop }
  285.      imagemask
  286.   grestore
  287. } def
  288.  
  289. % Here are the definitions needed to handle resident PostScript fonts:
  290.  
  291. /sp                                            % scaled pts to device dots
  292. { 16#10000 div                                % scaled pts to pts
  293.   res mul 72.27 div                        % pts to device dots
  294. } bind def
  295.  
  296. /PSfont                                        % uses dot size and TFM name
  297. { dup /Times-Slanted eq
  298.   {pop /Times-Roman findfont [1 0 .268 -1 0 0] makefont exch scalefont setfont}
  299.   {findfont [1 0 0 -1 0 0] makefont exch scalefont setfont}
  300.   ifelse
  301. } bind def
  302.  
  303. % End of OzTeX's prolog.
  304.